package ru.spbu.mm.diploma.client.service;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 *
 */
public class SessionService {

    private static SessionService instance = new SessionService();

    public static SessionService getInstance() {
        return instance;
    }

    private SessionService() {
    }

    public HttpSession getSession() {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        return session;
    }

    public HttpServletResponse getResponse() {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletResponse res = (HttpServletResponse) context.getExternalContext().getResponse();
        return res;
    }

    public boolean checkRights(Integer userroleID, String resourceID) {
        if (RightsService.rightsMap.containsKey(userroleID)) {
            List<String> grantedPages = RightsService.rightsMap.get(userroleID);
            if (grantedPages.contains(resourceID)) {
                return true;
            }
        }
        return false;
    }
}
